﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Runtime.Serialization;

namespace Bankeren.Engine.Cards
{
    /// <summary>
    /// This class represents the suit of a playingcard.
    /// </summary>
    [DataContract]
    public class Suit : IComparable<Suit>
    {
        #region Fields

        private string name;
        private char symbol;

        #endregion

        #region Suits

        /// <summary>
        /// Heart suit.
        /// </summary>
        public static readonly Suit Hearts = new Suit("Hearts", 'h');

        /// <summary>
        /// Clubs suit.
        /// </summary>
        public static readonly Suit Clubs = new Suit("Clubs", 'k');

        /// <summary>
        /// Diamonds suit.
        /// </summary>
        public static readonly Suit Diamonds = new Suit("Diamonds", 'r');

        /// <summary>
        /// Spades suit.
        /// </summary>
        public static readonly Suit Spades = new Suit("Spades", 's');

        /// <summary>
        /// No suit.
        /// </summary>
        public static readonly Suit None = new Suit("None", 'b');

        /// <summary>
        /// List of all suits.
        /// </summary>
        public static readonly Suit[] List = { Hearts, Clubs, Diamonds, Spades };

        #endregion

        #region Properties

        /// <summary>
        /// The suits name.
        [DataMember]
        public string Name
        {
            get
            {
                return this.name;
            }
            private set
            {
                this.name = value;
            }
        }

        /// <summary>
        /// The suits symbol.
        /// </summary>
        [DataMember]
        public char Symbol
        {
            get
            {
                return this.symbol;
            }
            private set
            {
                this.symbol = value;
            }
        }

        #endregion

        #region Ctor

        /// <summary>
        /// Private constructor for suit.
        /// </summary>
        /// <param name="name">The suits name.</param>
        /// <param name="symbol">The suits symbol.</param>
        private Suit(string name, char symbol)
        {
            this.Name = name;
            this.Symbol = symbol;
        }

        #endregion

        #region Methods

        /// <summary>
        /// Override of the default ToString().
        /// </summary>
        /// <returns>The suits name.</returns>
        public override string ToString()
        {
            return this.Name;
        }

        /// <summary>
        /// For comparing suits. (For sorting purposes)
        /// </summary>
        /// <param name="other">The suit for comparing.</param>
        /// <returns>A negative int if this suit is smaller,
        /// 0 if the suits are the same and a positive int if this suit is bigger.</returns>
        public int CompareTo(Suit other)
        {
            return this.Symbol - other.Symbol;
        }

        public override bool Equals(object obj)
        {
            Suit suit = obj as Suit;
            if (suit == null)
                return false;
            if (this.symbol == suit.symbol)
                return true;
            return false;
        }

        #endregion
    }
}
